home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_Event.c
-
- Contains: Event dispatching and event handlers.
-
- Written by: David H Nelson
-
- Copyright © 1993-1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <3> 04/23/95 RB Moving CADispatchMenuEvent() to Menu_HandleMenu()
- Added Adjust menu calls to Event_DoMouseInMenuBar()
- <2> 01/17/95 DAS changed all FrontWindow() calls to
- App_GetFrontDocWindow() to account for
- floating windows.
- 12/22/94 DHN Created from existing Light software
- application.
- ---------------
- <1> 11/20/93 DHN Created.
- */
-
- #ifdef USE_CALIB
- #include "CALib.h"
- #endif
-
- #include "CAS_Globals.h"
- #include "CAS_Misc.h"
- #include "CAS_App.h"
- #include "CAS_Win.h"
- #include "CAS_Event.h"
- #include "CAS_HelpBalloon.h"
- #include "CAS_AppleEvent.h"
- #include "CAS_Menu.h"
-
-
- //----------------------------------------------------------------------
- // local prototypes
-
- #if defined(__cplusplus)
- extern "C"
- {
- #endif
-
- static void Event_DoMouseInSysWindow(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInMenuBar(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInDrag(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInGoAway(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInZoomIn(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInZoomOut(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInGrow(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoMouseInContent(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoKeyDownEvent(
- EventRecord *theEvent,
- WindowPtr theWindow );
- static void Event_DoCmdKeyDownEvent(
- EventRecord *theEvent,
- WindowPtr theWindow );
-
- #if defined(__cplusplus)
- }
- #endif
-
- //---------------------------------------------------------------------------
-
- Boolean Event_DoubleClick(
- EventRecord *theEvent )
- {
- return
- ((TickCount() - gMouseUpTickCount < LMGetDoubleTime())
- && bAlmostEqual( theEvent->where, gMouseUpPoint, 4 ));
- }
-
- //---------------------------------------------------------------------------
- // Event_DoIdle - calls appIdle to let the application do any idle tasks, then handles
- // any standard idle tasks.
-
- void Event_DoIdle( void )
- {
- WindowPtr theWindow;
-
- theWindow = App_GetFrontDocWindow();
-
- App_Idle( theWindow );
- doBalloonHelp( theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleNullEvent(
- EventRecord *theEvent )
- {
- Event_DoIdle();
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInSysWindow(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- SystemClick( theEvent, theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInMenuBar(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- long mSelector;
-
- #ifdef USE_CALIB
-
- if (gCALibExists)
- {
- OSErr theErr;
-
- CAAdjustMenus();
- if (theErr = CAError())
- ; // handle the error
- }
-
- #endif
-
- Menu_AdjustMenus(theWindow);
-
- mSelector = MenuSelect( theEvent->where );
-
- Menu_HandleMenu( mSelector, theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInDrag(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- // if it's a doc window, select it and drag it.
- if (Win_IsAppWindow( theWindow ) ||
- (CAIsPartWindow (theWindow) == kCADocumentWindow))
- {
- // DragWindow looks for the special case where the dragRect is the size
- // of screenBits.bounds so this should work on multi-monitor systems.
- Rect dragRect = qd.screenBits.bounds; // $$$$$ a fine choice?
-
- // select the window.
- App_SetFrontDocWindow( theWindow ); // was SelectWindow()
-
- // Drag the window (was DragWindow()). $$$$$ This will not inherit new DragWindow behavior.
- Win_DragWindow_Better( theWindow, theEvent->where, &dragRect );
-
- // see if the app wants to adjust anything.
- App_Drag( theWindow );
- }
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInGoAway(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- if (TrackGoAway( theWindow, theEvent->where ))
- {
- // if the option key is down, close all the windows.
- if (gOptionPressed)
- App_CloseAll();
- else
- Win_Close( theWindow, NULL );
- }
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInZoomIn(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- if (TrackBox( theWindow, theEvent->where, inZoomIn ))
- {
- EraseRect( &theWindow->portRect );
- ZoomWindow( theWindow, inZoomIn, false );
- App_ZoomIn( theWindow );
- }
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInZoomOut(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- if (TrackBox( theWindow, theEvent->where, inZoomOut ))
- {
- EraseRect( &theWindow->portRect );
- ZoomWindow( theWindow, inZoomOut, false );
- App_ZoomOut( theWindow );
- }
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInGrow(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- Rect wBounds, growRect;
- Handle theRectHandle;
- long theResult;
-
- growRect = theWindow->portRect;
- growRect.left = growRect.right - (SBARWIDTH-1);
- growRect.top = growRect.bottom - (SBARWIDTH-1);
-
- // if the cmd key is down, just use our bounds above.
- if (!gCmdPressed)
- {
- // otherwise get the bounds from the wrct resource.
- theRectHandle = GetIndResource( 'wrct', 1 );
- if (theRectHandle != nil)
- wBounds = **(Rect**)theRectHandle;
- }
-
- SetRect( &wBounds, 140, 110, 32767, 32767 );
- theResult = GrowWindow( theWindow, theEvent->where, &wBounds );
- if (theResult != 0L)
- {
- SizeWindow( theWindow, LoWord( theResult ), HiWord( theResult ), true );
-
- InvalRect( &growRect );
-
- App_Grow( theWindow );
-
- DrawGrowIcon( theWindow );
- }
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoMouseInContent(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- if (Win_IsAppWindow( theWindow ))
- {
- if (theWindow != App_GetFrontDocWindow())
- App_SetFrontDocWindow( theWindow );
- else
- {
- SetPort( (GrafPtr)theWindow );
- App_MouseInContent( theEvent, theWindow );
- }
- }
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleMouseDownEvent(
- EventRecord *theEvent )
- {
- WindowPtr theWindow;
- short windowCode;
-
- windowCode = FindWindow( theEvent->where, &theWindow );
- if ((theWindow != nil) && (windowCode != inMenuBar))
- SetPort( (GrafPtr)theWindow );
-
- switch (windowCode)
- {
- case inSysWindow:
- Event_DoMouseInSysWindow( theEvent, theWindow );
- break;
-
- case inMenuBar:
- // click in menu bar applies to frontDocWindow, not theWindow
- Event_DoMouseInMenuBar( theEvent, App_GetFrontDocWindow() );
- //Event_DoMouseInMenuBar( theEvent, theWindow );
- break;
-
- case inDrag:
- Event_DoMouseInDrag( theEvent, theWindow );
- break;
-
- case inContent:
- Event_DoMouseInContent( theEvent, theWindow );
- break;
-
- case inGoAway:
- Event_DoMouseInGoAway( theEvent, theWindow );
- break;
-
- case inZoomIn:
- Event_DoMouseInZoomIn( theEvent, theWindow );
- break;
-
- case inZoomOut:
- Event_DoMouseInZoomOut( theEvent, theWindow );
- break;
-
- case inGrow:
- Event_DoMouseInGrow( theEvent, theWindow );
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleMouseUpEvent(
- EventRecord *theEvent )
- {
- // save the ticks and position of the mouse for double-click checking
- gMouseUpTickCount = TickCount();
- gMouseUpPoint = theEvent->where;
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoKeyDownEvent(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- App_Key(
- theWindow,
- theEvent->message & (charCodeMask | keyCodeMask),
- theEvent->modifiers );
- }
-
- //---------------------------------------------------------------------------
-
- static void Event_DoCmdKeyDownEvent(
- EventRecord *theEvent,
- WindowPtr theWindow )
- {
- App_CmdKey( theWindow, theEvent->message & charCodeMask, theEvent->modifiers );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleKeyDownEvent(
- EventRecord *theEvent )
- {
- long aMenu;
- WindowPtr theWindow;
-
- theWindow = App_GetFrontDocWindow();
- if (theEvent->modifiers & cmdKey)
- {
-
- #ifdef USE_CALIB
-
- if (gCALibExists)
- {
- OSErr theErr;
-
- CAAdjustMenus();
- if (theErr = CAError())
- ; // handle the error
- }
-
- #endif
-
- App_AdjustMenus (theWindow);
- aMenu = MenuKey( (char)(theEvent->message & charCodeMask) );
- if (aMenu != 0L)
- Menu_HandleMenu( aMenu, theWindow );
- else
- Event_DoCmdKeyDownEvent( theEvent, theWindow );
- }
- else
- Event_DoKeyDownEvent( theEvent, theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleAutoKeyEvent(
- EventRecord *theEvent )
- {
- long aMenu;
- WindowPtr theWindow;
-
- theWindow = App_GetFrontDocWindow();
- if (theEvent->modifiers & cmdKey)
- {
- aMenu = MenuKey( (char)(theEvent->message & charCodeMask) );
- if (aMenu != 0L)
- Menu_HandleMenu( aMenu, theWindow );
- else
- Event_DoCmdKeyDownEvent( theEvent, theWindow );
- }
- else
- Event_DoKeyDownEvent( theEvent, theWindow );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleKeyUpEvent(
- EventRecord *theEvent )
- {
- }
-
- //---------------------------------------------------------------------------
- // Event_HandleActivateEvent - SetPort the window, call doActivate or doDeactivate
- // depending upon the event modifier.
-
- void Event_HandleActivateEvent(
- EventRecord *theEvent )
- {
- WindowPtr theWindow;
-
- // if there is a window and it's ours, handle it.
- theWindow = (WindowPtr)theEvent->message;
- if (Win_IsAppWindow( theWindow ))
- {
- if (theEvent->modifiers & activeFlag)
- App_Activate( theWindow );
- else
- App_Deactivate( theWindow );
- }
-
-
- }
-
- //---------------------------------------------------------------------------
- // Event_HandleUpdateEvent - SetPort the window. BeginUpdate, call appUpdate, EndUpdate.
- // also handle updates for dialogs by calling DrawDialog.
-
- void Event_HandleUpdateEvent(
- EventRecord *theEvent )
- {
- WindowPtr theWindow;
- GrafPtr savePort;
-
- // get the window from the event.
- theWindow = (WindowPtr)(theEvent->message);
-
- GetPort( &savePort );
- SetPort( theWindow );
-
- // if there is a window and it's ours, update it.
- if (Win_IsAppWindow( theWindow ))
- {
- Win_Update (theWindow);
- }
- // if the window is a dialog, draw it.
- else if (Win_IsDialogWindow( theWindow ))
- {
- //BeginUpdate( theWindow );
- DrawDialog( theWindow );
- //EndUpdate( theWindow );
- }
-
- SetPort( savePort );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleHighLevelEvent(
- EventRecord *theEvent )
- {
-
- AE_DoAppleEvent( theEvent );
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleOSEvent(
- EventRecord *theEvent )
- {
- Boolean isSuspendEvent;
-
- switch ((theEvent->message >> 24) & 0x0FF)
- {
- case mouseMovedMessage:
- Event_DoIdle(); // mouseMovedMessage is also an idle event
- if (!gInBackground)
- App_AdjustCursor( App_GetFrontDocWindow(), theEvent->where, gMouseRgn );
- break;
-
- case suspendResumeMessage:
- isSuspendEvent = ((theEvent->message & resumeFlag) == 0L);
-
- gInBackground = isSuspendEvent;
-
- if (isSuspendEvent)
- {
- App_Suspend();
- }
- else
- {
- App_Resume();
- }
- App_ShowHideToolWindows( !gInBackground );
- break;
-
- default:
- break;
- }
- }
-
- //---------------------------------------------------------------------------
-
- void Event_HandleDiskEvent(
- EventRecord *theEvent )
- {
- Point thePt;
-
- if (HiWord( theEvent->message ) != 0)
- {
- thePt.h = thePt.v = 0x40;
- DIBadMount( thePt, theEvent->message );
- }
- }
-
-